var PanelView = function(parentElement,source){
	this.parentElement = parentElement;
	this.source = source;
	this.template = Handlebars.compile(this.source);
	this.element = document.createElement('div');
	this.element.setAttribute('class','panel');

	return this;
};

PanelView.prototype = {
	render : function(context,options){
		var self = this;
		var _createScrollableDiv = function(){
			var scrollableDiv = document.createElement('div');
			scrollableDiv.setAttribute('class','scrollable');
			scrollableDiv.innerHTML = self.template(context);

			self.element.appendChild(scrollableDiv);	

			self.scroller = $(scrollableDiv).scroller({vScrollCSS:"myScrollBar"});
		}
		
		this.parentElement.append(this.element);

		if(options){
			if(options.scrollable || options.scrollable == undefined){
				_createScrollableDiv();
			}
			else {
				this.element.innerHTML = this.template(context);
			}
			if(options.id && typeof options.id == 'string')
				this.element.setAttribute('id',options.id);
			if(options.class && typeof options.class == 'string')
				this.element.setAttribute('class',this.element.getAttribute('class') + ' ' + options.class);
			if(options.onLoad && typeof options.onLoad == 'string')
				this.element.setAttribute('data-onLoad',options.onLoad);
			if(options.onUnload && typeof options.onUnload == 'string')
				this.element.setAttribute('data-onUnload',options.onUnload);

		}
		else {
			_createScrollableDiv();
		}

		return this;
	}
}

/**Older version
*
var PanelView = function(parentElement,source){
	this.parentElement = parentElement;
	this.source = source;
	this.template = Handlebars.compile(this.source);

	return this;
};

PanelView.prototype = {
	render : function(context,options){
		this.parentElement.html(this.template(context));

		if(options){
			if(options.scrollable || options.scrollable == undefined){
				this.scroller = new iScroll(this.parentElement[0]);
			}
			if(options.scrollToBottom){
				this.scroller.scrollTo(0,this.scroller.maxScrollY);
			}
		}
		else {
			// this.scroller = new iScroll(this.parentElement[0]);
		}
		return this;
	}
}
*
*/